package com.sp.scmdb.entity;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.sp.scmdb.common.DomainObject;

@MappedSuperclass
public class SuperLabelIO extends DomainObject{

	@Column(name = "empID")
	private int empID;

	@Column(name = "labelID")
	private int labelID;

	@Column(name = "lrmID")
	private int lrmID;

	@Column(name = "inTime")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime inTime;

	@Column(name = "outTime")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime outTime;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "empID", insertable = false, updatable = false)
	private Employee employee;

	@Column(name = "rmk")
	private String rmk;

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public DateTime getInTime() {
		return inTime;
	}

	public int getLabelID() {
		return labelID;
	}

	public void setLabelID(int labelID) {
		this.labelID = labelID;
	}

	public int getLrmID() {
		return lrmID;
	}

	public void setLrmID(int lrmID) {
		this.lrmID = lrmID;
	}

	public void setInTime(DateTime inTime) {
		this.inTime = inTime;
	}

	public DateTime getOutTime() {
		return outTime;
	}

	public void setOutTime(DateTime outTime) {
		this.outTime = outTime;
	}

	public String getRmk() {
		return rmk;
	}

	public void setRmk(String rmk) {
		this.rmk = rmk;
	}

	public int getEmpID() {
		return empID;
	}

	public void setEmpID(int empID) {
		this.empID = empID;
	}
	
	public String getInTimeString(){
		if (null != this.inTime) {
			return this.inTime.toString("yyyy-MM-dd HH:mm:ss");			
		}
		return null;
	}
	
	public String getOutTimeString(){
		if (null != this.outTime){
			return this.outTime.toString("yyyy-MM-dd HH:mm:ss");
		}
		return null;
	}

	public void setInTimeString(String inTimeString){
		if (StringUtils.isNotEmpty(inTimeString)) {
			DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");			
			this.inTime = formatter.parseDateTime(inTimeString);
		}
	}
	
	public void setOutTimeString(String outTimeString){
		if (StringUtils.isNotEmpty(outTimeString)) {
			DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
			this.outTime = formatter.parseDateTime(outTimeString);
		}
	}
}
